package com.acceptable.qucun.generic.util.verify;

import java.util.Collection;
import java.util.Map;

public class FormatVerifyUtil {
    private final static String email = "^[A-Za-z0-9\\u4e00-\\u9fa5_]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+$";
    private final static String password = "^.{6,16}$";
    private final static String verifyCode = "^\\d+$";
    private final static String nickname = "^[^\\s]{1,16}$";
    private final static String repeatpwd = "^.{6,16}$";

    public static boolean isEmail(String value){
        return value.matches(email);
    }

    public static boolean isPassword(String value){
        return value.matches(password);
    }

    public static boolean isVerifyCode(String value){
        return value.matches(verifyCode);
    }

    public static boolean isNickname(String value) {return value.matches(nickname);}

    public static boolean isRepeatpwd(String value) {return value.matches(repeatpwd);}

    public static boolean isValidData(String value, String regex){
        return value.matches(regex);
    }

    public static boolean collectionIsEmpty(Collection<? extends Object> col){
        return col == null || col.size() == 0;
    }

    public static boolean mapIsEmpty(Map map){
        return map == null || collectionIsEmpty(map.keySet());
    }

    public static boolean arrayIsEmpty(Object[] array){
        return array == null || array.length == 0;
    }

}